//
// Created by Scave on 2024/2/22.
//
#ifndef RIDER3D_BASICCOMPONENTS_H
#define RIDER3D_BASICCOMPONENTS_H

#include <vector>
#include "Define.h"
#include "Supposition.h"
#include "resource/Resource.h"

NS_RIDER_BEGIN

    struct EntityIdentifier {
        Name name;
        UInt16 view_id;
    };

    struct Transform {
        Vec3 translation = {0, 0, 0};
        Quaternion rotation;
        Vec3 scale = {1, 1, 1};
        Vec3 center = Vectors::Invalid;
    };

    enum struct ProjectionType {
        Perspective = 0,
        Orthographic
    };

    struct Camera {
        // 在屏幕上的视口区域
        Rect view_port;
        Vec3 position = {0, 0, 2};
        Vec3 target = {0, 0, 0};
        Vec3 up_axis = {0, 1, 0};
        ProjectionType projection_type = ProjectionType::Perspective;
        // 透视投影模式下角度
        float field_of_view = 60;
        // 正射投影模式下视口大小
        float orthographic_size = 5;
        // 近裁剪平面
        float near_clip_plane = 0.1;
        // 远裁剪平面
        float far_clip_plane = 100;
    };

    enum struct RenderType {
        Triangles = 0,
        TrisStrip,
        Lines,
        LineStrip,
        Points,
    };

    struct RenderModel {
        Material material;
        RenderType render_type{RenderType::Triangles};
        bool visible = true;
        bool dynamic_vertices = false;
        bool lighting_enabled = true;
        float point_size = 3.f;
    };

    struct Mesh {
        Mesh();
        ~Mesh();

        void AddVertex(Vertex& vertex);

        void AddIndex(UInt16 index);

        void AddFace(Vertex& v1, Vertex& v2, Vertex& v3);

        void AddQuad(Vertex& bottom_left, Vertex& bottom_right, Vertex& top_right, Vertex& top_left);

        void SetVertices(UInt16 vertices_count, Vertex* vertices);

        void SetIndices(UInt16 indices_count, UInt16* indices);

        UInt16 VertexSize() const;

        UInt16 IndexSize() const;

        std::vector<Vertex> vertex_data_list{};
        std::vector<UInt16> vertex_index_list{};
    };

    struct MeshRenderModel : public RenderModel {
        Mesh* mesh = new Mesh;
    };

    struct InstancingRenderModel : public MeshRenderModel {
        std::vector<Transform> model_transforms;
    };

    struct SceneConfig {
        // 场景中的环境光色(默认太阳光)
        Color ambient_color{1.0f, 0.98f, 0.95f, 1.f};
    };

    enum struct LightType {
        Directional = 0,
        Point,
        Spot,
    };

    struct LightAttenuation {
        float constant = 1.0;
        float linear = 0.09;
        float quadratic = 0.032;
    };

    struct Light {
        LightType type = LightType::Directional;
        Color color = Colors::White;
        float strength = 1;
        float range = 1;
        // 衰减参数
        LightAttenuation attenuation = LightAttenuation();
        // 聚光灯角度
        float spotAngle;
    };

    struct DebugInfo {
        UInt16 x = 0, y = 0;
        UInt8 color = 0x0f;
        const char* text = nullptr;
    };

NS_RIDER_END
#endif //RIDER3D_BASICCOMPONENTS_H
